"""
@author: peng
@email: sb.peng@hzgosun.com
@file: misiCheckTest.py
@time: 2019/5/27 10:44

IMSI检索页面自动化测试用例
"""

import unittest
from time import sleep

from selenium.webdriver.common.keys import Keys

from common.functions import save_screenshot
from common.decorators import mkdir_classname, log4gs
from common.settings import TAG, DATA_DIR
from common.vue.select import DropDownSelect, OperateSelect
from pages.imsiCheckPage import misiPage

@log4gs
@mkdir_classname(TAG)
class IMSI_Test(unittest.TestCase):
    """imsi检索功能测试"""
    @classmethod
    def setUpClass(cls):
        cls.log.info('=' * 30 + "开始imsi检索功能测试({})".format(__class__.__name__) + '=' * 30)
        cls.page = misiPage('/DevManage/imsiManage')

    @classmethod
    def tearDownClass(cls):
        cls.log.info('=' * 30 + "结束imsi检索功能测试({})".format(__class__.__name__) + '=' * 30)
        cls.page.driver.quit()

    def setUp(self):
        self.log.info('>>>>>开始执行用例：{} {}'.format(self.id(), self.shortDescription()))

    def tearDown(self):
        self.log.info('<<<<<结束执行用例：{} {}'.format(self.id(), self.shortDescription()))

    @unittest.skip
    def test_page(self):
        """举例：翻页"""
        self.log.debug("当前共有：" + self.page.turnPage.total_page +"页数据" )
        self.log.debug("当前处于第：" + self.page.turnPage.current_page + "页数据")
        self.assertEqual(self.page.turnPage.current_page, '1')
        sleep(1)
        try:
            self.page.searchTools.start_time.clear()
            self.page.searchTools.search_btn.click()
            self.assertNotEqual(self.page.turnPage.total_page, 1, msg="页数过少，无法进行翻页测试")
            self.page.turnPage.next_page.click()
            self.assertEqual(self.page.turnPage.current_page, '2')

            sleep(1)
            self.page.turnPage.next_page.click()
            self.assertEqual(self.page.turnPage.current_page, '3')

            sleep(1)
            self.page.turnPage.prev_page.click()
            self.assertEqual(self.page.turnPage.current_page, '2')

            sleep(1)
            self.page.turnPage.input.clear()
            self.page.turnPage.input.send_keys(6)
            self.page.turnPage.input.send_keys(Keys.ENTER)
            self.assertEqual(self.page.turnPage.current_page, '6')
        except Exception:
            self.log.error("当前模块最大为1页，无法进行翻页测试", exc_info=True)

    # @unittest.skip
    def test_search_1(self):
        """IMSI查询"""
        self.page.searchTools.imsi_input.click()
        self.page.searchTools.imsi_input.send_keys('460017145624015')
        sleep(1)
        self.page.searchTools.start_time.send_keys('2019-05-27 17:45:50 - 2019-05-27 17:45:50')
        sleep(1)
        self.page.searchTools.search_btn.click()  # 点击检索按钮
        sleep(1)
        self.page.searchTools.search_btn.click()  # 点击检索按钮
        sleep(1)

        result = self.page.table.get_row("460017145624015")
        self.assertTrue(result, "通过序列号:查到了460017145624015")
        sleep(1)
        save_screenshot(self, "IMSI查询成功截图示例")
        sleep(1)

    # @unittest.skip
    def test_search_2(self):
        """时间"""
        self.page.searchTools.imsi_input.clear()
        # self.page.searchTools.imsi_community_dropdown_list.clear()
        # self.page.searchTools.start_time.click()
        sleep(1)
        # self.page.searchTools.start_time.clear()
        sleep(1)
        self.page.searchTools.start_time.send_keys('2019-05-31 14:29:09 - 2019-05-31 14:29:09')
        sleep(1)
        self.page.searchTools.search_btn.click()  # 点击检索按钮
        sleep(1)
        self.page.searchTools.search_btn.click()
        self.page.searchTools.start_time.send_keys('2019-05-27 17:45:50 - 2019-05-31 17:45:50')
        sleep(1)
        self.page.searchTools.search_btn.click()  # 点击检索按钮
        sleep(1)
        self.page.searchTools.search_btn.click()
        sleep(1)
        result = self.page.table.get_row("460017145624015")
        self.assertTrue(result, "通过区域:广西壮族自治区-南宁市-青秀区，小区：金湖小区查询到了460017145624015")
        # self.page.searchTools.reset_btn.click()  # 点击重置按钮
        sleep(1)
        save_screenshot(self, "事件查询imsi成功截图")

    # @unittest.skip
    def test_search_3(self):
        """区域、小区查询"""
        self.page.searchTools.imsi_input.clear()
        sleep(1)
        self.page.searchTools.imsi_region.click()
        sleep(1)
        self.page.searchTools.imsi_region_selector.select("河南省-郑州市-二七区")
        sleep(2)
        DropDownSelect(self.page.searchTools.community_dropdown_list, "金海小区")
        sleep(2)
        self.page.searchTools.start_time.send_keys('2019-05-27 11:20:18 - 2021-05-31 17:45:50')
        sleep(1)
        self.page.searchTools.search_btn.click()  # 点击检索按钮
        sleep(2)
        # self.page.searchTools.search_btn.click()  # 点击检索按钮
        # sleep(1)
        result = self.page.table.get_row("460017145624015")
        try:
            self.assertTrue(result, msg="通过查询：金湖小区,查询到460017145624015")
            self.log.info("查询460017145624015用例执行成功")
        except Exception:
            self.log.error("查询460017145624015用例执行失败", exc_info=True)
            save_screenshot('查询460017145624015用例执行失败')
        sleep(1)


if __name__ == '__main__':
    unittest.main()


